package com.ruoyi.web.controller.apps;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppModuleCate;
import com.ruoyi.system.service.IAppModuleCateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * APP组件分类Controller
 *
 * @author marion
 * @date 2023-07-09
 */
@RestController
@RequestMapping("/system/cate")
public class AppModuleCateController extends BaseController
{
    @Autowired
    private IAppModuleCateService appModuleCateService;

    /**
     * 查询APP组件分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:cate:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppModuleCate appModuleCate)
    {
        startPage();
        List<AppModuleCate> list = appModuleCateService.selectAppModuleCateList(appModuleCate);
        return getDataTable(list);
    }

    /**
     * 导出APP组件分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:cate:export')")
    @Log(title = "APP组件分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppModuleCate appModuleCate)
    {
        List<AppModuleCate> list = appModuleCateService.selectAppModuleCateList(appModuleCate);
        ExcelUtil<AppModuleCate> util = new ExcelUtil<AppModuleCate>(AppModuleCate.class);
        util.exportExcel(response, list, "APP组件分类数据");
    }

    /**
     * 获取APP组件分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appModuleCateService.selectAppModuleCateById(id));
    }

    /**
     * 新增APP组件分类
     */
    @PreAuthorize("@ss.hasPermi('system:cate:add')")
    @Log(title = "APP组件分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppModuleCate appModuleCate)
    {
        return toAjax(appModuleCateService.insertAppModuleCate(appModuleCate));
    }

    /**
     * 修改APP组件分类
     */
    @PreAuthorize("@ss.hasPermi('system:cate:edit')")
    @Log(title = "APP组件分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppModuleCate appModuleCate)
    {
        return toAjax(appModuleCateService.updateAppModuleCate(appModuleCate));
    }

    /**
     * 删除APP组件分类
     */
    @PreAuthorize("@ss.hasPermi('system:cate:remove')")
    @Log(title = "APP组件分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appModuleCateService.deleteAppModuleCateByIds(ids));
    }
}
